import {AbilityModel} from "../../controller/model/AbilityModel";
import Configer from "../../frame/apiModel/config/Configer";
import {FinalKey} from "../../constant/FinalConstant";
import {UnitController} from "../../controller/UnitController";
import {Logger} from "../../frame/apiModel/config/Logger";
import {UnitModel} from "../../frame/apiModel/adapterModel/model3/UnitModel";
import {ItemModel} from "../../frame/apiModel/adapterModel/model3/ItemModel";
import {PlayerModel} from "../../frame/apiModel/adapterModel/model4/PlayerModel";
import {LocModel} from "../../frame/apiModel/base/LocModel";
import {PlayerFactory} from "../../frame/PlayerFactory";
import {DataRouterUtil} from "../../utils/router/DataRouterUtil";
import {CodeUtil} from "../../frame/codeAdapter/CodeUtil";
import {AttributeEnum} from "../../frame/dataSource/DataModel";
import {Util} from "../../utils/Util";
import {AbilityUtil} from "./AbilityUtil";

export default class MustCatchPetSkillModel extends AbilityModel {
    abilityId: string = Configer.getFinal(FinalKey.mustCatchSkill) as string;

    actionFun = (activeUnit: UnitModel, activeItem: ItemModel, targetUnit: UnitModel, targetItem: ItemModel, activePlayer: PlayerModel, targetPlayer: PlayerModel, spellId: string, spellLoc: LocModel)  => {
        let success;
        const index = UnitController.getInstance().getFirstPetNullIndex(activePlayer);
        if (index >= 0) {
            const currentLifePercent = targetUnit.lifePercent;
            let probability = 0;
            if (currentLifePercent > 50) {
                probability = activePlayer.getRandomInt(1, 100);
            } else {
                Logger.toastProduct('触发条件！必定捕捉！', activePlayer)
            }
            success = AbilityUtil.catchPet(activeUnit, targetUnit, index, probability);
        } else {
            Logger.toastProduct('您没有空余兽栏了', activePlayer)
            success = false;
        }
        return success;
    }
}